# 高可用配置搭配Sentinel機制
---> Redis (Replica)
client ---> Redis (Master)
---> Redis (Replica)
-------------------------------------------------
sentinel
# 高可用配置搭配Sentinel叢集架構
---> Redis (Replica)
client ---> Redis (Master)
---> Redis (Replica)
-------------------------------------------------
sentinel sentinel sentinel
# 複製三份設定檔,結尾用Port命名
cp sentinel_26379.conf sentinel_26380.conf
cp sentinel_26379.conf sentinel_26381.conf
# 修改各個設定檔中的port與monitor需要設定成2,搭配目前redis server (Master) 127.0.0.1 6380
# sentinel_26379.conf
vi sentinel_26379.conf
port 26379
daemonize yes
logfile "/tmp/redis-sentinel_26379.log"
dir "/tmp"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
# sentinel_26380.conf
vi sentinel_26380.conf
port 26380
daemonize yes
logfile "/tmp/redis-sentinel_26380.log"
dir "/tmp"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
# sentinel_26381.conf
vi sentinel_26381.conf
port 26381
daemonize yes
logfile "/tmp/redis-sentinel_26381.log"
dir "/tmp"
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
# 啟動三個sentinel
./redis-sentinel sentinel_26379.conf
./redis-sentinel sentinel_26380.conf
./redis-sentinel sentinel_26381.conf
# 確認是否正常運作
ps -ef|grep redis-se
為什麼sentinel monitor 組態需要特別設定2個以上(多數) 的sentinel才可以決定選出新的Redis Server 的Master,因為有可能因爲網路的延遲造成某個sentinel監控Redis Server Master時發生誤判,進而直接就切換到了別台Redis Master.
Master離線機制